package planit.util;

import java.util.Calendar;
import java.util.Date;

@SuppressWarnings("serial")
public class ExtendedDate extends Date {

	public static Date dateWithAddedMinutes(Date date, int minutes) {
		return new Date(date.getTime() + minutes * 60 * 1000);
	}
	public static Date dateWithAddedDays(Date date, int days) {
		return new Date(date.getTime() + days*24*60 * 60 * 1000);
	}

	public static Date createDateTime(int year, int month, int date, int hour,
			int minute) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date, hour, minute);
		return cal.getTime();
	}

	public static Date createDate(int year, int month, int date) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date, 0, 0);
		return cal.getTime();
	}

	public static Date createDate() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		return cal.getTime();
	}

	public static boolean isSameDay(Date d1, Date d2){
		//return (d1.compareTo(d2) == 0);
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(d1);
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(d2);

		/*
		System.out.println( cal1.get(Calendar.YEAR)  + " " +  cal2.get(Calendar.YEAR)   + "  " + 
		cal1.get(Calendar.MONTH)  + " " + cal2.get(Calendar.MONTH)  + "  " + 
		cal1.get(Calendar.DATE)   + " " + cal2.get(Calendar.DATE)); */
		return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
		cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
		cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE); 
	}

	public static int daysBetween(Date startDay, Date endDay) {
		return (minutesBetween(startDay, endDay) / 60 / 24);
	}

	public static int minutesBetween(Date startTime, Date endTime) {
		return (int) ( ( (endTime.getTime() - startTime.getTime() ) / 1000 ) / 60);
	}

}
